package demo6;

public class Teat2 {
    public static void main(String[] args) {
        Animal animal = new Dog("大黄",6);
        if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.bark();
        }
        else if (animal instanceof Cat){
            Cat cat = (Cat) animal;
            cat.tell();
        }
    }
    public static void main4(String[] args) {
        Animal animal = new Dog("小黑",10);
        animal.eat();

        Dog dog = (Dog)animal;//向下转型
        dog.bark();
        System.out.println("============");
//        Cat cat = (Cat)animal;
//        cat.tell();
    }
    public static Animal getAnimal(int a) {
        if(a == 1) {
            return new Dog("小黑",10);
        }
        else{
            return new Cat("咪咪",5);
        }

    }
    public static void main3(String[] args) {
        Animal animal = getAnimal(1);//作为返回值
        animal.eat();
    }
    public static void main2(String[] args) {
        Animal animal = new Dog("小黑",10);//直接赋值
        //animal.bark();

    }
    public static void eat(Animal animal) {
        animal.eat();
    }
    public static void main1(String[] args) {
        Dog dog = new Dog("大黑",15);

        Cat cat = new Cat("小小",14);

        eat(dog);//方法传参
        eat(cat);//方法传参
    }
}
